package client;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.geom.Ellipse2D;

public class Ball {

	private Ellipse2D ball;
	private int xSpeed = -5, ySpeed = 2;
	private final int DEFAULT_X_SPEED = 5;
	
	public Ball(int x, int y, int radius) {
		ball = new Ellipse2D.Double(x, y, radius*2, radius*2);
	}
	
	public void move() {
		ball.setFrame(getX()+xSpeed, getY()+ySpeed, getDiameter(), getDiameter());
	}
	
	public void setSpeeds(int xSpeed, int ySpeed) {
		this.xSpeed = xSpeed;
		this.ySpeed = ySpeed;
	}
	
	public void setXSpeed(int xSpeed) {
		this.xSpeed = xSpeed;
	}
	
	public void setYSpeed(int ySpeed) {
		this.ySpeed = ySpeed;
	}
	
	public void incrementXSpeed() {
		if(Math.abs(xSpeed) + DEFAULT_X_SPEED > 15) {
			return;
		}
		if(xSpeed < 0) {
			xSpeed--;
		} else {
			xSpeed++;
		}
	}
	
	public void inverseXSpeed() {
		xSpeed *= -1;
	}
	
	public void inverseYSpeed() {
		ySpeed *= -1;
	}	
	
	public int getXSpeed() {
		return xSpeed;
	}
	
	public int getYSpeed() {
		return ySpeed;
	}
	
	public int getRadius() {
		return (int) ball.getWidth()/2;
	}
	
	public int getDiameter() {
		return (int) ball.getWidth();
	}
	
	public int getX() {
		return (int) ball.getX();
	}
	
	public int getY() {
		return (int) ball.getY();
	}
	
	public Ellipse2D getBall() {
		return ball;
	}
	
	public void drawOntoGraphics(Graphics g) {
		g.setColor(Color.GREEN);
		g.fillOval(getX(), getY(), getDiameter(), getDiameter());
	}
	
}
